package top.sqdpt.wechat.handler;

import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutTextMessage;
import org.springframework.util.StringUtils;

import java.util.Map;


public class TextWxMsgHandler implements WxMpMessageHandler {

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) {
        String fromUser = wxMessage.getFromUser();
        String toUser = wxMessage.getToUser();
        String userMsg = wxMessage.getContent();
        if (!StringUtils.hasText(userMsg)) {
            return null;
        }
        //调用AI回答问题
        String aiMsg = "";

        return WxMpXmlOutTextMessage
                .TEXT()
                .toUser(fromUser)
                .fromUser(toUser)
                .content(aiMsg)
                .build();
    }

}
